/**
 * Copyright (c) 2010 Simple Graph Tools contributors. All rights reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 *  
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 *
 * $Id$
 */
package org.sgt.datamodel.impl;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.util.EMap;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENamedElementImpl;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.util.EcoreEMap;
import org.eclipse.emf.ecore.util.InternalEList;
import org.sgt.datamodel.Action;
import org.sgt.datamodel.ActionSpecification;
import org.sgt.datamodel.DataStore;
import org.sgt.datamodel.DatamodelPackage;
import org.sgt.datamodel.Executor;
import org.sgt.datamodel.Value;
import org.sgt.datamodel.util.ExecutionException;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Action</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.sgt.datamodel.impl.ActionImpl#getSpecification <em>Specification</em>}</li>
 *   <li>{@link org.sgt.datamodel.impl.ActionImpl#getInputs <em>Inputs</em>}</li>
 *   <li>{@link org.sgt.datamodel.impl.ActionImpl#getOutputs <em>Outputs</em>}</li>
 *   <li>{@link org.sgt.datamodel.impl.ActionImpl#getParameters <em>Parameters</em>}</li>
 *   <li>{@link org.sgt.datamodel.impl.ActionImpl#getExecutor <em>Executor</em>}</li>
 *   <li>{@link org.sgt.datamodel.impl.ActionImpl#getDataStore <em>Data Store</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class ActionImpl extends ENamedElementImpl implements Action {
	/**
	 * The cached value of the '{@link #getSpecification() <em>Specification</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getSpecification()
	 * @generated
	 * @ordered
	 */
	protected ActionSpecification specification;

	/**
	 * The cached value of the '{@link #getInputs() <em>Inputs</em>}' map.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getInputs()
	 * @generated
	 * @ordered
	 */
	protected EMap<String, Value> inputs;

	/**
	 * The cached value of the '{@link #getOutputs() <em>Outputs</em>}' map.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getOutputs()
	 * @generated
	 * @ordered
	 */
	protected EMap<String, Value> outputs;

	/**
	 * The cached value of the '{@link #getParameters() <em>Parameters</em>}' map.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getParameters()
	 * @generated
	 * @ordered
	 */
	protected EMap<String, Value> parameters;

	/**
	 * The cached value of the '{@link #getExecutor() <em>Executor</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getExecutor()
	 * @generated
	 * @ordered
	 */
	protected Executor executor;

	/**
	 * The cached value of the '{@link #getDataStore() <em>Data Store</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDataStore()
	 * @generated
	 * @ordered
	 */
	protected DataStore dataStore;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected ActionImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return DatamodelPackage.Literals.ACTION;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public ActionSpecification getSpecification() {
		if (specification != null && specification.eIsProxy()) {
			InternalEObject oldSpecification = (InternalEObject)specification;
			specification = (ActionSpecification)eResolveProxy(oldSpecification);
			if (specification != oldSpecification) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, DatamodelPackage.ACTION__SPECIFICATION, oldSpecification, specification));
			}
		}
		return specification;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public ActionSpecification basicGetSpecification() {
		return specification;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setSpecification(ActionSpecification newSpecification) {
		ActionSpecification oldSpecification = specification;
		specification = newSpecification;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, DatamodelPackage.ACTION__SPECIFICATION, oldSpecification, specification));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EMap<String, Value> getInputs() {
		if (inputs == null) {
			inputs = new EcoreEMap<String,Value>(DatamodelPackage.Literals.VALUE_MAP, ValueMapImpl.class, this, DatamodelPackage.ACTION__INPUTS);
		}
		return inputs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EMap<String, Value> getOutputs() {
		if (outputs == null) {
			outputs = new EcoreEMap<String,Value>(DatamodelPackage.Literals.VALUE_MAP, ValueMapImpl.class, this, DatamodelPackage.ACTION__OUTPUTS);
		}
		return outputs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EMap<String, Value> getParameters() {
		if (parameters == null) {
			parameters = new EcoreEMap<String,Value>(DatamodelPackage.Literals.VALUE_MAP, ValueMapImpl.class, this, DatamodelPackage.ACTION__PARAMETERS);
		}
		return parameters;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Executor getExecutor() {
		if (executor != null && executor.eIsProxy()) {
			InternalEObject oldExecutor = (InternalEObject)executor;
			executor = (Executor)eResolveProxy(oldExecutor);
			if (executor != oldExecutor) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, DatamodelPackage.ACTION__EXECUTOR, oldExecutor, executor));
			}
		}
		return executor;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Executor basicGetExecutor() {
		return executor;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setExecutor(Executor newExecutor) {
		Executor oldExecutor = executor;
		executor = newExecutor;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, DatamodelPackage.ACTION__EXECUTOR, oldExecutor, executor));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public DataStore getDataStore() {
		if (dataStore != null && dataStore.eIsProxy()) {
			InternalEObject oldDataStore = (InternalEObject)dataStore;
			dataStore = (DataStore)eResolveProxy(oldDataStore);
			if (dataStore != oldDataStore) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, DatamodelPackage.ACTION__DATA_STORE, oldDataStore, dataStore));
			}
		}
		return dataStore;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public DataStore basicGetDataStore() {
		return dataStore;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setDataStore(DataStore newDataStore) {
		DataStore oldDataStore = dataStore;
		dataStore = newDataStore;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, DatamodelPackage.ACTION__DATA_STORE, oldDataStore, dataStore));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void buildFromSpecification() {
		// TODO: implement this method
		// Ensure that you remove @generated or mark it @generated NOT
		throw new UnsupportedOperationException();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void execute() throws ExecutionException {
		// TODO: implement this method
		// Ensure that you remove @generated or mark it @generated NOT
		throw new UnsupportedOperationException();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case DatamodelPackage.ACTION__INPUTS:
				return ((InternalEList<?>)getInputs()).basicRemove(otherEnd, msgs);
			case DatamodelPackage.ACTION__OUTPUTS:
				return ((InternalEList<?>)getOutputs()).basicRemove(otherEnd, msgs);
			case DatamodelPackage.ACTION__PARAMETERS:
				return ((InternalEList<?>)getParameters()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case DatamodelPackage.ACTION__SPECIFICATION:
				if (resolve) return getSpecification();
				return basicGetSpecification();
			case DatamodelPackage.ACTION__INPUTS:
				if (coreType) return getInputs();
				else return getInputs().map();
			case DatamodelPackage.ACTION__OUTPUTS:
				if (coreType) return getOutputs();
				else return getOutputs().map();
			case DatamodelPackage.ACTION__PARAMETERS:
				if (coreType) return getParameters();
				else return getParameters().map();
			case DatamodelPackage.ACTION__EXECUTOR:
				if (resolve) return getExecutor();
				return basicGetExecutor();
			case DatamodelPackage.ACTION__DATA_STORE:
				if (resolve) return getDataStore();
				return basicGetDataStore();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case DatamodelPackage.ACTION__SPECIFICATION:
				setSpecification((ActionSpecification)newValue);
				return;
			case DatamodelPackage.ACTION__INPUTS:
				((EStructuralFeature.Setting)getInputs()).set(newValue);
				return;
			case DatamodelPackage.ACTION__OUTPUTS:
				((EStructuralFeature.Setting)getOutputs()).set(newValue);
				return;
			case DatamodelPackage.ACTION__PARAMETERS:
				((EStructuralFeature.Setting)getParameters()).set(newValue);
				return;
			case DatamodelPackage.ACTION__EXECUTOR:
				setExecutor((Executor)newValue);
				return;
			case DatamodelPackage.ACTION__DATA_STORE:
				setDataStore((DataStore)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case DatamodelPackage.ACTION__SPECIFICATION:
				setSpecification((ActionSpecification)null);
				return;
			case DatamodelPackage.ACTION__INPUTS:
				getInputs().clear();
				return;
			case DatamodelPackage.ACTION__OUTPUTS:
				getOutputs().clear();
				return;
			case DatamodelPackage.ACTION__PARAMETERS:
				getParameters().clear();
				return;
			case DatamodelPackage.ACTION__EXECUTOR:
				setExecutor((Executor)null);
				return;
			case DatamodelPackage.ACTION__DATA_STORE:
				setDataStore((DataStore)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case DatamodelPackage.ACTION__SPECIFICATION:
				return specification != null;
			case DatamodelPackage.ACTION__INPUTS:
				return inputs != null && !inputs.isEmpty();
			case DatamodelPackage.ACTION__OUTPUTS:
				return outputs != null && !outputs.isEmpty();
			case DatamodelPackage.ACTION__PARAMETERS:
				return parameters != null && !parameters.isEmpty();
			case DatamodelPackage.ACTION__EXECUTOR:
				return executor != null;
			case DatamodelPackage.ACTION__DATA_STORE:
				return dataStore != null;
		}
		return super.eIsSet(featureID);
	}

} //ActionImpl
